<?php
/**
 * Profile View for Congregation Component
 * 
 * @package    Congregation
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_4
 * @license		GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view' );

/**
 * Profile View
 *
 * @package    Congregation
 * @subpackage Components
 */
class CongregationViewProfile extends CongregationView
{
	
	
	function display($tpl = null)
	{
		$document =& JFactory::getDocument(); 
		$document->addScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
		$document->addScript(JRoute::_('administrator/components/com_congregation/js/congregation.js'));
		// Get data from the model
		$profile =& $this->get('Data');
		
		
		//$profiles =& $this->get('List');
		$model =& $this->getModel('profile');
		
		$user =& $model->getUser(array('where' => array("username = '{$profile->username}'")));
		$this->assignRef('name', $user->name);
		
		$statuses = $model->getStatusList();
		$this->assignRef('statuses', $statuses);
		
		$languages = array('it' => JText::_('Italian'), 'pt' => JText::_('Portuguese'), 'es' => JText::_('Spanish'), 'en' => JText::_('English'), 'fr' => JText::_('French'));
		$this->assignRef('languages', $languages);
		
		$houses = $model->getHouseList();
		$this->assignRef('houses', $houses);

		$isNew		= ($profile->id < 1);
		$this->assignRef('profiles', $profiles);
		
		$freeusers =& $this->get('FreeUsers');
		$this->assignRef('freeusers', $freeusers);
		
		
		
		if($isNew)
		{
			JToolBarHelper::title(   JText::_( 'New Profile' ), 'generic.png' );
			$profile->c_id = JRequest::getVar('c_id');
		}
		else
		{
			JToolBarHelper::title(   JText::_( 'Edit Profile' ), 'generic.png' );
		}
		
		$this->assignRef('profile', $profile);
		JToolBarHelper::save();

		JToolBarHelper::back(JText::_('Back'), JRoute::_( 'index.php?option=com_congregation&controller=profile&c_id=' . $profile->c_id));
		
		
		

		parent::display($tpl);
	}
	
}
